<?php

// 返回分类连接
function getcatelink($cid, $url) {
	global $options;
	if ($options['permalink']) {
		if ($url) {
			return $options['url'].'category/'.$url.'/';
		} else {
			return $options['url'].'category/'.$cid.'/';
		}
	} else {
		return $options['url'].'?cid='.$cid;
	}
}

function getrsslink($cid = 0, $url = '') {
	global $options;
	if ($options['permalink']) {
		if ($url) {
			$permalink = $options['url'].'rss/'.$url.'/';
		} else {
			$permalink = $options['url'].'rss/'.($cid ? $cid.'/' : '');
		}
		return $permalink;
	} else {
		return $options['url'].'rss.php'.($cid ? '?cid='.$cid : '');
	}
}

function gettaglink($tag) {
	global $options;
	if ($options['permalink']) {
		return $options['url'].'tag/'.urlencode($tag).'/';
	} else {
		return $options['url'].'?action=article&amp;item='.urlencode($tag);
	}
}

function getdatelink($setdate) {
	global $options;
	if ($options['permalink']) {
		return $options['url'].'date/'.$setdate.'/';
	} else {
		return $options['url'].'?action=article&amp;setdate='.$setdate;
	}
}

function getpagelink($action = '') {
	global $options;
	if ($options['permalink']) {
		return $options['url'].$action.'/';
	} else {
		return $options['url'].'?action='.$action;
	}
}

function getpermalink($articleid, $alias = '', $page = 0, $date = 0, $category = '') {
	global $options;
	if ($options['permalink']) {
		if ($alias) {
			if($category) {
				$permalink = $options['url'].$alias.'/'.($page ? $page.'/' : '');
			} else {
				$permalink = $options['url'].$date.'/'.$alias.'/'.($page ? $page.'/' : '');
			}
		} else {
			if($category) {
				$permalink = $options['url'].$alias.'/'.($page ? $page.'/' : '');
			} else {
				$permalink = $options['url'].$date.'/'.$articleid.'/'.($page ? $page.'/' : '');
			}
		}
		return $permalink;
	} else {
		return $options['url'].'?action=show&amp;id='.$articleid.($page ? '&amp;page='.$page : '');
	}
}

function redirect_permalink($url, $alias = '', $page = 0, $date = 0, $category = '') {
	return str_replace('&amp;', '&', getpermalink($url, $alias, $page, $date, $category));
}

function getuserlink($userinfo, $isname = true) {
	global $options;
	if ($options['permalink']) {
		if ($isname) {
			return $options['url'].'user/'.urlencode($userinfo).'/';
		} else {
			return $options['url'].'uid/'.$userinfo.'/';
		}
	} else {
		if ($isname) {
			return $options['url'].'?action=finduser&amp;user='.urlencode($userinfo);
		} else {
			return $options['url'].'?action=finduser&amp;uid='.$userinfo;
		}
	}
}

?>